<template>
    <div>

        <EditAddSubchanceDialog ref="AddSubchanceDialogRef" :visible="addSubchanceDialogVisible" :close="closeAddSubchance"
                            :callback="addSubchance" :options="options"></EditAddSubchanceDialog>
        <EditAddCompetitionDialog ref="AddCompetitionDialogRef" :visible="addCompetitionDialogVisible"
                              :close="closeAddCompetition" :callback="addCompetition"
                              :options="options"></EditAddCompetitionDialog>
        <EditAddPurchaseDialog ref="AddPurchaseDialogRef" :visible="addPurchaseDialogVisible" :close="closeAddPurchase"
                           :callback="addPurchase" :options="options"></EditAddPurchaseDialog>



        <EditSubchanceDialog ref="EditSubchanceDialogRef" :visible="editSubchanceDialogVisible"
                             :close="closeEditSubchance" :callback="editSubchance"
                             :options="options"></EditSubchanceDialog>
        <EditCompetitionDialog ref="EditCompetitionDialogRef" :visible="editCompetitionDialogVisible"
                               :close="closeEditCompetition" :callback="editCompetition"
                               :options="options"></EditCompetitionDialog>
        <EditPurchaseDialog ref="EditPurchaseDialogRef" :visible="editPurchaseDialogVisible" :close="closeEditPurchase"
                            :callback="editPurchase" :options="options"></EditPurchaseDialog>


        <el-dialog :visible.sync="visible" :before-close="handleCloseAddChance" @close="confirmCloseAddChance"
                   :fullscreen="fullscreen" width="90%" top="4vh">

            <div slot="title">
                <div
                    style=" width:50%;display: flex;align-items: center;justify-content: space-between;border-bottom: #99a9bf 1px solid;padding-bottom: 10px">
                    <span style="font-weight: bold">Edit Chance</span>
                    <div>
                        <el-button size="small" type="primary" icon="el-icon-upload" @click="handleUpload">Upload
                        </el-button>

                    </div>
                </div>


            </div>
            <div class="fullscreen" @click="onFullScreenClick">
                <i class="el-icon-full-screen"/>
            </div>


            <el-row :gutter="20">
                <el-col :span="12">

                    <el-card shadow="never" class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-weight:bold">Chance Info</span>
                        </div>

                        <el-form ref="elForm-addChance" :model="editChanceForm" :rules="addChanceRules" size="medium"
                                 label-width="100px"
                                 label-position="left">
                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="chanceId" label-width="80px" prop="chanceId">
                                        <el-input v-model="editChanceForm.chanceId" clearable :disabled="true"
                                                  :style="{width: '60%'}">
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="Chance Name" label-width="140px" prop="chanceName">
                                        <el-input v-model="editChanceForm.chanceName"
                                                  placeholder="Please enter chanceName" clearable
                                                  :style="{width: '100%'}">
                                        </el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="Customer Name" label-width="140px" prop="customerName">
                                        <el-select v-model="editChanceForm.customerName" placeholder="Please Enter"
                                                   filterable clearable
                                                   :style="{width: '100%'}">
                                            <el-option v-for="(item, index) in options.customerNameOptions" :key="index"
                                                       :label="item.label"
                                                       :value="item.value" :disabled="item.disabled"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>

                            </el-row>

                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label="ChanceResource" label-width="150px" prop="chanceResource">
                                        <el-select v-model="editChanceForm.chanceResource" placeholder="Please enter"
                                                   filterable clearable
                                                   :style="{width: '100%'}">
                                            <el-option v-for="(item, index) in options.chanceResourceOptions"
                                                       :key="index" :label="item.label"
                                                       :value="item.value" :disabled="item.disabled"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="Chance Phase" label-width="140px" prop="chancePhase">
                                        <el-select v-model="editChanceForm.chancePhase" placeholder="Please choose"
                                                   filterable clearable
                                                   :style="{width: '100%'}">
                                            <el-option v-for="(item, index) in options.chancePhaseOptions" :key="index"
                                                       :label="item.label"
                                                       :value="item.value" :disabled="item.disabled"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="Chance Belong" label-width="140px" prop="chanceBelong">
                                        <el-select v-model="editChanceForm.chanceBelong" placeholder="Please choose"
                                                   filterable clearable
                                                   :style="{width: '100%'}">
                                            <el-option v-for="(item, index) in options.chanceBelongOptions" :key="index"
                                                       :label="item.label"
                                                       :value="item.value" :disabled="item.disabled"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>

                            </el-row>

                            <el-row :gutter="20">
                                <el-col :span="8">
                                    <el-form-item label-width="120px" label="Old Customer" prop="chanceOldCustomer">
                                        <el-switch v-model="editChanceForm.chanceOldCustomer"></el-switch>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="Chance Time" label-width="140px" prop="chanceTime">
                                        <el-date-picker v-model="editChanceForm.chanceTime" format="yyyy-MM-dd"
                                                        value-format="yyyy-MM-dd"
                                                        :style="{width: '100%'}" placeholder="Y-M-D"
                                                        clearable></el-date-picker>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8"></el-col>

                            </el-row>
                            <el-row :gutter="20">
                                <el-col :span="16">
                                    <el-form-item label-width="280px" label="Opportunity Background Statement"
                                                  prop="chanceBackground">
                                        <el-input v-model="editChanceForm.chanceBackground" type="textarea"
                                                  placeholder="Please Enter"
                                                  :autosize="{minRows: 2, maxRows: 5}"
                                                  :style="{width: '80%'}"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-button size="small" type="primary" icon="el-icon-check" @click="handleConfirmAddChance">
                                        Confirm
                                    </el-button>

                                    <el-button size="small" icon="el-icon-refresh-left" @click="handleCancelAddChance">
                                        Exit
                                    </el-button>
                                </el-col>

                            </el-row>

                        </el-form>

                    </el-card>

                    <el-card shadow="never" class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-weight:bold">Subchance List</span>
                            <el-button size="small" type="primary" icon="el-icon-plus" @click="openAddSubchanceDialog" style="float: right">New
                            </el-button>
                        </div>

                        <el-table :data="subchanceTable"  :header-cell-style="{fontSize:'12px',background:'#eef1f6',color:'#495085'}" show-summary>
                            <el-table-column
                                type="index"
                                width="50"
                                label="Index">
                            </el-table-column>
                            <el-table-column property="subchanceName" label="subchanceName"></el-table-column>
                            <el-table-column property="subchanceType" label="subchanceType"></el-table-column>
                            <el-table-column property="subchanceProduct" label="subchanceProduct"></el-table-column>
                            <el-table-column property="subchanceDept" label="subchanceDept"></el-table-column>
                            <el-table-column property="subchanceMoney" label="subchanceMoney"></el-table-column>
                            <el-table-column label="Operate">
                                <template slot-scope="scope">

                                    <el-button
                                        size="mini"
                                        type="primary"
                                        circle
                                        icon="el-icon-edit"
                                        @click="handleEditSubChance(scope.$index, scope.row)">
                                    </el-button>

                                    <el-button
                                        size="mini"
                                        type="danger"
                                        icon="el-icon-delete"
                                        @click="handleDeleteSubChance(scope.$index, scope.row)" circle>
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>


                    </el-card>

                </el-col>


                <el-col :span="12">

                    <el-card shadow="never" class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-weight:bold">Approval flow chart</span>
                        </div>
                        <div>
                            <el-steps :space="300" :active="parseInt(editChanceForm.chanceStatus)" align-center>
                                <el-step title="Submitter"></el-step>
                                <el-step title="vice president of marketing"></el-step>
                                <el-step title="Sales Director/General Manager of Business"></el-step>
                            </el-steps>
                        </div>

                    </el-card>

                    <el-card shadow="never" class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-weight:bold"> Approval Report </span>

                        </div>

                        <el-table  :header-cell-style="{fontSize:'12px',background:'#eef1f6',color:'#495085'}" :data="approvalTable">

                            <el-table-column property="approvalId" label="id"></el-table-column>
                            <el-table-column property="approvalName" label="name"></el-table-column>
                            <el-table-column property="approvalMember" label="member"></el-table-column>
                            <el-table-column property="approvalStatus" label="status"></el-table-column>
                            <el-table-column property="approvalHandleAdvice" label="handleAdvice"></el-table-column>
                            <el-table-column property="approvalAdvice" label="advice"></el-table-column>
                            <el-table-column property="approvalTime" label="apply time"></el-table-column>

                        </el-table>
                    </el-card>



                    <el-card shadow="never" class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-weight:bold"> Competition </span>

                                                        <el-button size="small" type="primary" icon="el-icon-plus" @click="openAddCompetitionDialog" style="float: right">New
                                                        </el-button>

                        </div>

                        <el-table  :header-cell-style="{fontSize:'12px',background:'#eef1f6',color:'#495085'}" :data="competitionTable">
                            <el-table-column
                                type="index"
                                width="50"
                                label="Index">
                            </el-table-column>
                            <el-table-column property="competitionRival" label="competitionRival"></el-table-column>
                            <el-table-column property="competitionPotential"
                                             label="competitionPotential"></el-table-column>

                            <el-table-column label="Operate">
                                <template slot-scope="scope">

                                    <el-button
                                        size="mini"
                                        type="primary"
                                        icon="el-icon-edit"
                                        @click="handleEditCompetition(scope.$index, scope.row)" circle>
                                    </el-button>

                                    <el-button
                                        size="mini"
                                        type="danger"
                                        @click="handleDeleteCompetition(scope.$index, scope.row)" circle icon="el-icon-delete">
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-card>

                    <el-card shadow="never" class="box-card">
                        <div slot="header" class="clearfix">
                            <span style="font-weight:bold"> Purchase decision maker information </span>

                                                        <el-button size="small" type="primary" icon="el-icon-plus" @click="handleAddPurchase" style="float: right">New
                                                        </el-button>

                        </div>

                        <el-table  :header-cell-style="{fontSize:'12px',background:'#eef1f6',color:'#495085'}" :data="purchaseTable">

                            <el-table-column property="purchaseName" label="name"></el-table-column>
                            <el-table-column property="purchaseDept" label="dept"></el-table-column>
                            <el-table-column property="purchasePosition" label="position"></el-table-column>
                            <el-table-column property="purchasePhone" label="phone"></el-table-column>
                            <el-table-column property="purchaseDecision" label="decision"></el-table-column>
                            <el-table-column property="purchaseEffect" label="effect"></el-table-column>
                            <el-table-column property="purchaseAccept" label="accept"></el-table-column>

                            <el-table-column label="Operate">
                                <template slot-scope="scope">

                                    <el-button
                                        size="mini"
                                        type="primary"
                                        icon="el-icon-edit"
                                        @click="handleEditPurchase(scope.$index, scope.row)" circle>
                                    </el-button>

                                    <el-button
                                        size="mini"
                                        icon="el-icon-delete"
                                        type="danger"
                                        @click="handleDeletePurchase(scope.$index, scope.row)" circle>
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>


                    </el-card>


                </el-col>
            </el-row>
        </el-dialog>


    </div>
</template>

<script>
import EditAddSubchanceDialog from "./InnerDialog/EditAddSubchanceDialog";
import EditAddCompetitionDialog from "./InnerDialog/EditAddCompetitionDialog";
import EditAddPurchaseDialog from "./InnerDialog/EditAddPurchaseDialog";
import EditSubchanceDialog from "@/views/NPMS/Chance/ChanceManage/Dialog/InnerDialog/EditSubchanceDialog";
import EditCompetitionDialog from "@/views/NPMS/Chance/ChanceManage/Dialog/InnerDialog/EditCompetitionDialog";
import EditPurchaseDialog from "@/views/NPMS/Chance/ChanceManage/Dialog/InnerDialog/EditPurchaseDialog";

export default {
    name: "EditChanceDialog",
    components: {
        EditPurchaseDialog,
        EditCompetitionDialog, EditSubchanceDialog, EditAddPurchaseDialog, EditAddCompetitionDialog, EditAddSubchanceDialog
    },
    props: ['visible', 'options', 'close', 'callback'],
    data() {
        return {

            fullscreen: false,
            indexChance: null,

            //sub-dialog-visible
            addSubchanceDialogVisible: false,
            addCompetitionDialogVisible: false,
            addPurchaseDialogVisible: false,

            editSubchanceDialogVisible: false,
            editCompetitionDialogVisible: false,
            editPurchaseDialogVisible: false,

            //修改机会的对话框表单
            editChanceForm: {
                chanceId: 1,
                chanceCode: "",
                chanceName: undefined,
                chanceResource: undefined,
                chancePhase: undefined,
                chanceTime: null,
                customerMgrDept: undefined,
                customerMgrName: undefined,
                chanceStatus: "1",
                chanceType: undefined,

                customerName: "",
                chanceBelong: undefined,
                chanceOldCustomer: false,
                chanceBackground: undefined,


            },

            addChanceRules: {
                chanceName: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'blur'
                }],
                customerName: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'blur'
                }],
                chanceResource: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'change'
                }],
                chancePhase: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'change'
                }],
                chanceBelong: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'change'
                }],
                chanceTime: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'change'
                }],
                chanceBackground: [{
                    required: true,
                    message: 'Please Enter',
                    trigger: 'blur'
                }],
            },

            subchanceTable: [{
                subchanceName: 'name',
                subchanceType: 'type',
                subchanceProduct: 'product',
                subchanceDept: 'dept',
                subchanceMoney: '500',
            }, {
                subchanceName: 'name',
                subchanceType: 'type',
                subchanceProduct: 'product',
                subchanceDept: 'dept',
                subchanceMoney: '200',
            }],

            competitionTable: [{
                competitionRival: 'Google',
                competitionPotential: 'equal',
            }, {
                competitionRival: 'Google',
                competitionPotential: 'equal',
            }],

            purchaseTable: [{
                purchaseName: 'xxx',
                purchaseDept: 'xxx',
                purchasePosition: 'xxx',
                purchasePhone: 'xxx',
                purchaseDecision: 'xxx',
                purchaseEffect: 'xxx',
                purchaseAccept: 'xxx',
            }, {
                purchaseName: 'xxx',
                purchaseDept: 'xxx',
                purchasePosition: 'xxx',
                purchasePhone: 'xxx',
                purchaseDecision: 'xxx',
                purchaseEffect: 'xxx',
                purchaseAccept: 'xxx',
            }],

            //          机会审批日志
            approvalTable: [{
                approvalId:1,
                approvalName: 'xxx',
                approvalMember: 'xxx',
                approvalStatus: 'xxx',
                approvalAdvice: 'xxx',
                approvalTime: 'xxx',

                approvalHandleAdvice: 'agree',
                approvalUploader: 'xxx',
                approvalUptime: 'xxx',
            }],
            newApproval: {
                approvalId:null,
                approvalName: null,
                approvalMember: null,
                approvalStatus: null,
                approvalAdvice: null,
                approvalTime: null,

                approvalHandleAdvice: null,
                approvalUploader: null,
                approvalUptime: null,
            }
        }
    },

    methods: {

        //获取所有的客户名字和编号，用于创建edit chance
        init() {

            this.$axios.post(
                '/customer/customer/queryAllCustomer',
            ).then(res => {
                // console.log(res.data.obj);

                this.options.customerNameOptions = [];

                for (var i = 0; i < res.data.obj.length; i++) {
                    var item = {
                        "label": "",
                        "value": ""
                    }
                    item.label = res.data.obj[i].customerName
                    item.value = res.data.obj[i].customerId
                    this.options.customerNameOptions.push(item)
                }
                console.log(this.options.customerNameOptions)
            });

            // this.editChanceForm.chanceId = currentId

        },

        //从后端获取子机会、竞争、购买人的数据，增删改查后使用刷新列表
        loadChance() {

            this.$axios.post(
                '/chance/chance/searchSubchance/' + this.editChanceForm.chanceId
            ).then(res => {
                this.subchanceTable.length = 0
                // console.log("abc"+res.data.obj)
                this.subchanceTable = res.data.obj
            });

            this.$axios.post(
                '/chance/chance/searchCompetition/' + this.editChanceForm.chanceId
            ).then(res => {
                this.competitionTable.length = 0
                // console.log("abc"+res.data.obj)
                this.competitionTable = res.data.obj
            });

            this.$axios.post(
                '/chance/chance/searchPurchase/' + this.editChanceForm.chanceId
            ).then(res => {
                this.purchaseTable.length = 0
                // console.log("abc"+res.data.obj)
                this.purchaseTable = res.data.obj
            });

        },


        //全屏
        onFullScreenClick() {
            this.fullscreen = !this.fullscreen
        },

        //修改机会确定
        handleConfirmAddChance() {
            console.log("edit chance");
            this.$refs['elForm-addChance'].validate(valid => {
                if (!valid) return

                this.$axios.post(
                    '/chance/chance/updateChance',
                    this.editChanceForm
                ).then(res => {
                    console.log(res.data.obj)

                    //如果当前机会不在暂存状态，则需要更改最新的审批状态
                    // console.log(this.editChanceForm.chanceStatus)
                    // if(this.editChanceForm.chanceStatus !== 'Draft'){
                    //     let dto = {
                    //         "chanceId": this.editChanceForm.chanceId,
                    //         "status": "Waiting For Approval"
                    //     }
                    //     this.$axios.post('/approve/approve/updateLatestApproval', dto).then(e => {
                    //         console.log("update approval status")
                    //         console.log(e)
                    //     })
                    // }

                    console.log('before close', this.editChanceForm);
                    //深拷贝
                    const dd = JSON.parse(JSON.stringify(this.editChanceForm))

                    this.$message({
                        message: "chance edit successfully!",
                        type: "success",
                    });

                    this.callback(dd, this.indexChance)
                    this.indexChance = null
                    this.close()
                });
            })
        },

        //新增机会取消
        handleCancelAddChance() {
            console.log("cancel chance");
            this.close();
        },

        //新增机会弹窗关闭的确认框
        handleCloseAddChance(done) {
            this.$confirm('Closing now will lose all unsaved data. Confirm closing?', {
                cancelButtonText: 'cancel',
                confirmButtonText: 'confirm'
            })
                // eslint-disable-next-line no-unused-vars
                .then(e => {
                    done();
                })
        },

        handleUpload() {
            this.editChanceForm.chanceStatus = 'Under Process'
            this.$axios.post(
                '/chance/chance/updateChance',
                this.editChanceForm
            )
            const tthis = this
            this.newApproval.approvalStatus = 'Waiting For Approval'
            this.newApproval.approvalAdvice = 'Modify after returned'
            let dto = {
                chanceId: this.editChanceForm.chanceId,
                role: this.$npms.roles.CUSTOMER_MGR,
                approval: this.newApproval,
            }
            this.$axios.post("/approve/approve/addChanceApproval", dto)
        },

        //关闭新增机会弹窗
        confirmCloseAddChance() {
            console.log("close the dialog");
            this.close();
        },

        //新增子机会弹窗
        openAddSubchanceDialog() {
            console.log("open Add Subchance Dialog");
            this.addSubchanceDialogVisible = true
            this.$nextTick(() => {
                this.$refs.AddSubchanceDialogRef.setData(this.editChanceForm.chanceId);
            })
        },

        //修改子机会
        handleEditSubChance(index, row) {
            console.log(index, row);
            this.editSubchanceDialogVisible = true;

            const data = JSON.parse(JSON.stringify(row))

            this.$nextTick(() => {
                this.$refs.EditSubchanceDialogRef.setData(data, index, this.editChanceForm.chanceId);
            })
        },

        //删除子机会
        handleDeleteSubChance(index, row) {
            // console.log(index, row);
            console.log(this.subchanceTable)
            console.log(row.subchanceId)


            this.$confirm('Are you sure you want to delete?', 'Tips', {
                confirmButtonText: 'Yes',
                cancelButtonText: 'No',
                type: 'warning'
            }).then(() => {
                console.log(index, row);

                // this.subchanceTable.splice(index, 1)

                this.$axios.post(
                    '/chance/chance/deleteSubchance/' + row.subchanceId,
                ).then(res => {
                    console.log(res.data.obj)
                    this.$message({
                        type: 'success',
                        message: 'successfully delete!'
                    });
                    this.loadChance()
                });
            })

        },

        //关闭子机会弹窗
        closeAddSubchance() {
            this.addSubchanceDialogVisible = false
        },

        //关闭子机会修改弹窗
        closeEditSubchance() {
            this.editSubchanceDialogVisible = false
        },

        //添加子机会点击后回调函数
        addSubchance(subchance) {

            this.loadChance()

            // this.subchanceTable.push(subchance)
            console.log(subchance)
        },

        //修改子机会点击后回调函数
        editSubchance(subchance, index) {

            this.loadChance()
            // this.subchanceTable.splice(index,1,subchance)
            console.log(subchance)
        },

        //新增竞争情况弹窗
        openAddCompetitionDialog() {
            console.log("open Add Competition Dialog");
            this.addCompetitionDialogVisible = true
            this.$nextTick(() => {
                this.$refs.AddCompetitionDialogRef.setData(this.editChanceForm.chanceId);
            })
        },

        //删除情况竞争
        handleDeleteCompetition(index, row) {
            // console.log(index, row);
            console.log(this.competitionTable)

            this.$confirm('Are you sure you want to delete?', 'Tips', {
                confirmButtonText: 'Yes',
                cancelButtonText: 'No',
                type: 'warning'
            }).then(() => {
                console.log(index, row);

                this.$axios.post(
                    '/chance/chance/deleteCompetition/' + row.competitionId,
                ).then(res => {
                    console.log(res.data.obj)
                    this.$message({
                        type: 'success',
                        message: 'successfully delete!'
                    });
                    this.loadChance()
                });

                // this.competitionTable.splice(index, 1)

            })
        },

        //修改竞争
        handleEditCompetition(index, row) {
            console.log(index, row);
            this.editCompetitionDialogVisible = true;

            const data = JSON.parse(JSON.stringify(row))

            this.$nextTick(() => {
                this.$refs.EditCompetitionDialogRef.setData(data, index, this.editChanceForm.chanceId);
            })

        },

        //关闭新增竞争情况弹窗
        closeAddCompetition() {
            this.addCompetitionDialogVisible = false
        },

        //关闭新增竞争情况修改弹窗
        closeEditCompetition() {
            this.editCompetitionDialogVisible = false
        },


        //添加竞争点击后回调函数
        addCompetition(competition) {
            this.loadChance()
            // this.competitionTable.push(competition)
            console.log(competition)
        },

        //修改竞争点击后回调函数
        editCompetition(competition, index) {
            this.loadChance()
            // this.competitionTable.splice(index,1,competition)
            console.log(competition)
        },

        //新增购买决策人
        handleAddPurchase() {
            console.log("Add Purchase");
            this.addPurchaseDialogVisible = true

            this.$nextTick(() => {
                this.$refs.AddPurchaseDialogRef.setData(this.editChanceForm.chanceId);
            })

        },

        //删除购买决策人
        handleDeletePurchase(index, row) {
            console.log(index, row);

            this.$confirm('Are you sure you want to delete?', 'Tips', {
                confirmButtonText: 'Yes',
                cancelButtonText: 'No',
                type: 'warning'
            }).then(() => {
                console.log(index, row);

                this.$axios.post(
                    '/chance/chance/deletePurchase/' + row.purchaseId,
                ).then(res => {
                    console.log(res.data.obj)
                    this.$message({
                        type: 'success',
                        message: 'successfully delete!'
                    });
                    this.loadChance()
                });

                // this.purchaseTable.splice(index, 1)

            })
        },


        //修改购买决策人
        handleEditPurchase(index, row) {
            console.log(index, row);

            this.editPurchaseDialogVisible = true;

            const data = JSON.parse(JSON.stringify(row))

            this.$nextTick(() => {
                this.$refs.EditPurchaseDialogRef.setData(data, index, this.editChanceForm.chanceId);
            })
        },

        //关闭购买决策人弹窗
        closeAddPurchase() {
            this.addPurchaseDialogVisible = false
        },

        //关闭购买决策人弹窗
        closeEditPurchase() {
            this.editPurchaseDialogVisible = false
        },

        //添加购买决策人点击后回调函数
        addPurchase(purchase) {

            this.loadChance()

            // this.purchaseTable.push(purchase)
            console.log(purchase)
        },

        //修改购买决策人回调函数
        editPurchase(purchase, index) {
            this.loadChance()
            // this.purchaseTable.splice(index,1,purchase)
            console.log(purchase)
        },

        //将表格中的数据传输到dialog中
        setData(data, index) {
            this.editChanceForm = data

            this.$axios.post(
                '/chance/chance/searchSubchance/' + data.chanceId
            ).then(res => {
                // console.log("abc"+res.data.obj)
                this.subchanceTable = res.data.obj
            });

            this.$axios.post(
                '/chance/chance/searchCompetition/' + data.chanceId
            ).then(res => {
                // console.log("abc"+res.data.obj)
                this.competitionTable = res.data.obj
            });

            this.$axios.post(
                '/chance/chance/searchPurchase/' + data.chanceId
            ).then(res => {
                // console.log("abc"+res.data.obj)
                this.purchaseTable = res.data.obj
            });

            this.$axios.post(
                '/approve/approve/getApprovalByChanceId/' + data.chanceId
            ).then(res => {
                // console.log("abc"+res.data.obj)
                this.approvalTable = res.data.obj
            });

            this.indexChance = index
        },
    },

}
</script>


<style scoped>

.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both
}

.box-card {
    margin-top: 10px;

}

.fullscreen {
    position: absolute;
    right: 50px;
    top: 18px;
    cursor: pointer;
    transition: all 200ms;
}

.fullscreen:hover {
    color: #6DBEF8;
}
</style>